﻿Public Class AudioObject
    Inherits ResourceObjectBase

    Public Property Instance() As SoundEffectInstance

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal name As String, ByVal fileName As String, ByVal snd As SoundEffect)
        MyBase.New(name, fileName)
        Me.Instance = snd.CreateInstance()
    End Sub

    ''' <summary>
    ''' Play the sound in background.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Play()
        Dim thr As New Threading.Thread(
            Sub(obj)
                Dim sndi = CType(obj, SoundEffectInstance)
                sndi.Play()
                While sndi.State = SoundState.Playing
                    System.Threading.Thread.Sleep(100)
                End While
            End Sub)
        thr.Start(Me.Instance)
    End Sub

End Class